package utils
import (
	"fmt"
)
type MyFamilyAccount struct{
	key string
	loop bool
	balance float64
	money float64
	note string
	flag bool
	details string
}
func MyFamilyAccountFactory() *MyFamilyAccount{
	return &MyFamilyAccount{
		key : "",
		loop : true,
		balance : 10000,
		money :0,
		note : "",
		flag : false,
		details : "收支\t账户金额\t收支金额\t说  明\t",
	}
}
func (this *MyFamilyAccount)ShowMenu(){
	for{
		fmt.Println("\n-----------家庭收支软件--------------")
		fmt.Println("		 	1、收支明细")
		fmt.Println("		 	2、登记收入")
		fmt.Println("		 	3、登记支出")
		fmt.Println("		 	4、退出系统")
		fmt.Printf("请选择（1-4）：")
		fmt.Scanln(&this.key)
		switch this.key {
		case "1":
			this.ShowDetails()
		case "2":
			this.Income()
		case "3":
			this.Pay()
		case "4":
			this.Quit()
		default:
			fmt.Println("你输入有误!")
		}
		if !this.loop {
			break
		}
	}
}
func (this *MyFamilyAccount)ShowDetails(){
	fmt.Println("-------------当前收支明细记录--------------")
			if this.flag{
				fmt.Println(this.details)
			}else{
				fmt.Println("当前还没有收支喔~来一笔~")
			}
}
func (this *MyFamilyAccount)Income(){
	fmt.Printf("本次收入金额：")
			fmt.Scanln(&this.money)
			this.balance += this.money
			fmt.Printf("本次收入说明：")
			fmt.Scanln(&this.note)
			this.details += fmt.Sprintf("\n收入\t%v\t%v\t%v",this.balance,this.money,this.note)
			this.flag = true
}
func (this *MyFamilyAccount)Pay(){
	fmt.Printf("本次支出金额：")
			fmt.Scanln(&this.money)
			if this.money > this.balance {
				fmt.Println("余额不足！")
				
			}
			this.balance -= this.money
			fmt.Printf("本次支出说明：")
			fmt.Scanln(&this.note)
			this.details += fmt.Sprintf("\n支出\t%v\t%v\t%v",this.balance,this.money,this.note)
			this.flag = true
}
func (this *MyFamilyAccount)Quit(){
	fmt.Printf("你确定要退出吗？（y/n）")
			choice := ""
			for {
				fmt.Scanln(&choice)
				if choice == "y" || choice == "n"{
					break
				}
				fmt.Printf("您输入有误，请重新输入：")
			}
			if choice == "y"{
				this.loop = false
			}
}